home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / patches / newalert / addmodule.asm < prev    next >
Assembly Source File  |  1996-04-07  |  4KB  |  196 lines

  1. ; Add Resident Module
  2. ; (c) 1994 MJSoft System Software
  3. ; Martin Mares
  4.  
  5. ;DEBUG    set    1
  6.  
  7.     include    "ssmac.h"
  8.  
  9.     rsreset            ; KickMem & KickTag structure
  10. kb_kickmem    rs.b    ML_SIZE
  11. kb_kicktag    rs.l    2
  12. kb_sizeof    rs.b    0
  13.  
  14.     clistart
  15.  
  16.     get.l    module,a0
  17.     move.l    #1005,d0
  18.     call    TrackOpen
  19.     pea    freefunc(pc)
  20.     pea    allocfunc(pc)
  21.     get.l    dosbase,a6
  22.     pea    _LVORead(a6)
  23.     move.l    sp,a1
  24.     sub.l    a0,a0
  25.     clr.l    -(sp)
  26.     move.l    sp,a2
  27.     call    InternalLoadSeg
  28.     lea    16(sp),sp
  29.     put.l    d0,seglist
  30.     dv.l    seglist
  31.     bne.s    segok
  32.     lea    errmsg(pc),a0
  33. moderr    geta    module,a1
  34.     jump    ss,ExitError
  35.  
  36. segok    move.l    d0,d7        ; D7=copy of SegList
  37.     lea    moderrt(pc),a0
  38.     lsl.l    #2,d0
  39.     move.l    d0,a1
  40.     move.l    -(a1),d0
  41.     lsr.l    #1,d0
  42.     subq.l    #3,d0
  43.     bmi.s    moderr
  44.     move.l    d0,d1
  45.     swap    d1
  46. findtag1    cmp.w    #RTC_MATCHWORD,(a1)+
  47. findtag2    dbeq    d0,findtag1
  48.     dbeq    d1,findtag1
  49.     bne.s    moderr
  50.     move.l    a1,d2
  51.     subq.l    #2,d2
  52.     cmp.l    (a1),d2        ; A1=D2+2
  53.     bne.s    findtag2    ; D2 contains address of ResidentTag
  54.  
  55.     get.l    class,d0    ; Set options
  56.     beq.s    noclass
  57.     move.l    d0,a0
  58.     move.l    (a0),d0
  59.     move.l    d0,d1
  60.     tst.b    RT_FLAGS-RT_MATCHTAG(a1)
  61.     bpl.s    1$
  62.     bset    #7,d0
  63. 1$    move.b    d0,RT_FLAGS-RT_MATCHTAG(a1)
  64.     lsr.l    #7,d1
  65.     lea    badclass(pc),a0
  66.     bne.s    moderr
  67.  
  68. noclass    get.l    pri,d0
  69.     beq.s    modok
  70.     move.l    d0,a0
  71.     move.l    (a0),d0
  72.     move.b    d0,RT_PRI-RT_MATCHTAG(a1)
  73.     ext.w    d0
  74.     ext.l    d0
  75.     cmp.l    (a0),d0
  76.     lea    badpri(pc),a0
  77.     bne.s    moderr
  78.  
  79. modok    move.l    RT_NAME-2(a1),a1    ; Test if not already present
  80.     call    exec,FindResident    
  81.     tst.l    d0
  82.     beq.s    notalre
  83.     move.l    d0,a0
  84.     move.l    d2,a1
  85.     moveq    #RT_VERSION,d0
  86.     add.l    d0,a0
  87.     add.l    d0,a1
  88.     cmp.b    (a1)+,(a0)+    ; Comprare version
  89.     bcs.s    notalre
  90.     cmp.b    (a1)+,(a0)+
  91.     cmp.b    (a1)+,(a0)+    ; Compare priorities
  92.     bcc    cl1        ; Already installed -- ignore
  93.  
  94. notalre    moveq    #kb_sizeof+8,d0    ; Calculate size of KickMem & KickTag
  95.     moveq    #1,d6
  96.     move.l    d7,d5        ; D5=SegList
  97. calcsize    lsl.l    #2,d7
  98.     addq.l    #8,d0
  99.     addq.l    #1,d6
  100.     move.l    d7,a0
  101.     move.l    (a0),d7
  102.     bne.s    calcsize
  103.     move.l    d0,d3        ; D3=KM+KT size
  104.     move.l    #MEMF_CLEAR+MEMF_PUBLIC,d1
  105.     move.l    4.w,a6
  106.     bsr.s    allocfunc
  107.     tst.l    d0
  108.     bne.s    tagok
  109.     moveq    #err_memory,d0
  110.     jump    ss,ReportError
  111.  
  112. tagok    move.l    d0,a0
  113.     lea    kb_kickmem+ML_NUMENTRIES(a0),a1
  114.     move.w    d6,(a1)+
  115.     move.l    a0,(a1)
  116.     subq.l    #8,(a1)+
  117.     move.l    d3,(a1)
  118.     addq.l    #8,(a1)+
  119. fillmem    lsl.l    #2,d5
  120.     move.l    d5,a2
  121.     move.l    -(a2),d0
  122.     move.l    a2,(a1)
  123.     subq.l    #8,(a1)+
  124.     addq.l    #8,d0
  125.     move.l    d0,(a1)+
  126.     move.l    4(a2),d5
  127.     bne.s    fillmem
  128.  
  129.     clrv.l    seglist
  130.     call    Forbid
  131.     lea    KickMemPtr(a6),a2
  132.     move.l    (a2),(a0)
  133.     move.l    a0,(a2)+
  134.     move.l    d2,(a1)+
  135.     move.l    (a2),(a1)
  136.     beq.s    1$
  137.     bset    #7,(a1)
  138. 1$    subq.l    #4,a1
  139.     move.l    a1,(a2)+
  140.     call    SumKickData
  141.     move.l    d0,(a2)
  142.     call    Permit
  143.  
  144.     tsv.l    callinit    ; Call module initialization if needed
  145.     beq.s    cl1
  146.     move.l    d2,a1
  147.     jump    InitResident
  148.  
  149. cleanup    get.l    seglist,d1
  150.     beq.s    cl1
  151.     lea    freefunc(pc),a1
  152.     call    dos,InternalUnLoadSeg
  153. cl1    rts
  154.  
  155. allocfunc    addq.l    #8,d0
  156.     mpush    d0/d1
  157.     or.l    #MEMF_REVERSE+MEMF_KICK,d1
  158.     call    AllocMem
  159.     tst.l    d0
  160.     bne.s    1$
  161.     movem.l    (sp),d0/d1
  162.     or.l    #MEMF_REVERSE+MEMF_LOCAL,d1
  163.     call    AllocMem
  164.     tst.l    d0
  165.     beq.s    2$
  166. 1$    addq.l    #8,d0
  167. 2$    addq.l    #8,sp
  168.     rts
  169.  
  170. freefunc    subq.l    #8,a1
  171.     addq.l    #8,d0
  172.     jump    FreeMem
  173.  
  174.     dc.b    '$VER: AddModule 1.2 (12.12.94)',0
  175. errmsg    dc.b    'Error loading %s',0
  176. moderrt    dc.b    '%s is not a resident module',0
  177. badclass    dc.b    'Class must be in range 0 to 127',0
  178. badpri    dc.b    'Priority must be in range -128 to 127',0
  179.     even
  180.  
  181.     tags
  182.     template    <MODULE/A,CLASS/K/N,PRI/K/N,INIT/S>
  183.     dv.l    module
  184.     dv.l    class
  185.     dv.l    pri
  186.     dv.l    callinit
  187.     extrahelp
  188.     dc.b    'Resident Module Adder 1.1 (c) 1993 Martin Mares, MJSoft System Software',10,10
  189.     dc.b    'Usage: AddModule <module> [CLASS <class>] [PRI <priority>] [INIT]',10
  190.     dc.b    'Switches: INIT - call initialization entry of the module after it''s added.',10
  191.     endhelp
  192.     exitrout cleanup
  193.     finish
  194.  
  195.     end
  196.